//
//  TimeLineCell.m
//  SunXi
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 大远. All rights reserved.
//

#import "TimeLineCell.h"

@implementation TimeLineCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createData];
    }
    return self;
}
- (void)createData {
    self.nameAndEnnameLab = [[UILabel alloc] init];
    self.nameAndEnnameLab.font = [UIFont systemFontOfSize:10];
    self.nameAndEnnameLab.textColor = [UIColor colorWithRed:0.553f green:0.553f blue:0.553f alpha:1.00f];
    [self.contentView addSubview:self.nameAndEnnameLab];
    
    self.middleImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.middleImageView];
    
    self.contentLab = [[UILabel alloc] init];
    self.contentLab.font = [UIFont systemFontOfSize:12];
    self.contentLab.textColor = [UIColor colorWithRed:0.325f green:0.325f blue:0.325f alpha:1.00f];
    self.contentLab.numberOfLines = 0;
    [self.contentView addSubview:self.contentLab];
    
//    self.contentLab.backgroundColor = [UIColor redColor];
    
}
- (void) layoutSubviews {
    [super layoutSubviews];
    
    [self.nameAndEnnameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(CHEIGHT / 390 * 10, CWIDTH / 375 * 20, CHEIGHT / 390 * 350, CWIDTH / 375 * 205));
        
    }];
    
    [self.middleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(CHEIGHT / 390 * 45, CWIDTH / 375 * 20, CHEIGHT / 390 * 120, CWIDTH / 375 * 20));
        
    }];
    
    
    [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(CHEIGHT / 390 * 300, CWIDTH / 375 * 20, CHEIGHT / 390 * 10, CWIDTH / 375 * 20));
        
    }];
    
}
- (void)setModel:(DataModel *)model {
    if (_model != model) {
        _model = [model retain];
        
        
        [self.middleImageView sd_setImageWithURL:[NSURL URLWithString:_model.coverimg] placeholderImage:[UIImage imageNamed:@"zan"]];
        NSString *nameAndEnnameStr = [NSString stringWithFormat:@"%@·%@", _model.name, _model.enname];
        self.nameAndEnnameLab.text = nameAndEnnameStr;
        self.contentLab.text = _model.content;
        
       
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.contentLab.text];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:10];//调整行间距
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.contentLab.text length])];
        self.contentLab.attributedText = attributedString;
        [self.contentLab sizeToFit];
        
        
    }
}







- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
